package com.driving.single.common.redis.service.impl;

import com.driving.single.common.redis.service.CommonRedisSchoolServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 驾校服务Redis接口实现类
 */
@Service
public class CommonRedisSchoolServiceServiceImpl implements CommonRedisSchoolServiceService {
    @Value("${redis_key_frontend_school_service}")
    private String redis_key_frontend_school_service;   // 驾校服务KEY
    @Value("${redis_key_frontend_school_expire_second}")
    private Integer redis_key_frontend_school_expire_second;   // 驾校过期时间(单位：秒)

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    /**
     * 缓存 驾校服务
     * @param tbSchoolServiceMap 驾校服务
     * @param school_id 驾校ID
     */
    @Override
    public Integer insertRedisTbSchoolService(Map<String, Object> tbSchoolServiceMap, Long school_id) {
        String key = this.redis_key_frontend_school_service + ":" + school_id;
        this.redisTemplate.opsForValue().set(key,tbSchoolServiceMap,this.redis_key_frontend_school_expire_second, TimeUnit.SECONDS);
        return 200;
    }
    /**
     * 查询缓存中的 驾校服务
     * @param school_id 主键
     */
    @Override
    public Map<String, Object> selectRedisTbSchoolServiceById(Long school_id) {
        String key = this.redis_key_frontend_school_service + ":" + school_id;
        return (Map<String, Object>) this.redisTemplate.opsForValue().get(key);
    }
}
